<!--47合金钢件疲劳强度计算（GL）-->
<template>
  <div class="sum" style="width: 100%;height: 100%;font-size: 16px">
    <a-row style="width: 100%;height: 100%;">
      <a-col :span="10" style="height: 100%;border-radius: 3px">
        <a-row style="height:40%;width: 100%" class="data_container">
          <a-row style="background: #D7D7D7;height: 8%;width: 100%;border-radius: 3px">S-N曲线输入参数</a-row>
          <a-row style=";height: 92%;width: 100%;">
            <a-col :span="12" style="height: 100%;text-align: center;">
              <a-col :span="12" style="height: 100%;margin-top: 3px">
                <a-row style="height: 16.6%;width: 100%;">抗拉强度(MPa)</a-row>
                <a-row style="height: 16.6%;width: 100%;">屈服强度(MPa)</a-row>
                <a-row style="height: 16.6%;width: 100%;">零件壁厚(mm)</a-row>
                <a-row style="height: 16.6%;width: 100%;">表面粗糙度(um)</a-row>
                <a-row style="height: 16.6%;width: 100%;">延伸率(%)</a-row>
                <a-row style="height: 17%;width: 100%;">可靠率(%)</a-row>
              </a-col>
              <a-col :span="12" style="height: 100%;margin-top: 3px">
                <a-row style="height: 16.6%;width: 100%;"><input type="text" v-model="input_data.Rm"/></a-row>
                <a-row style="height: 16.6%;width: 100%;"><input type="text" v-model="input_data.Rp"/></a-row>
                <a-row style="height: 16.6%;width: 100%;"><input type="text" v-model="input_data.t"/></a-row>
                <a-row style="height: 16.6%;width: 100%;"><input type="text" v-model="input_data.Rz"/></a-row>
                <a-row style="height: 16.6%;width: 100%;"><input type="text" v-model="input_data.Y"/></a-row>
                <a-row style="height: 17%;width: 100%;">97.5</a-row>
              </a-col>
            </a-col>
            <a-col :span="12" style="height: 100%; text-align: center">
              <a-col :span="12" style="height: 100%;margin-top: 3px">
                <a-row style="height: 16.6%;width: 100%;">应力集中系数</a-row>
                <a-row style="height: 16.6%;width: 100%;">内部材料支撑系数</a-row>
                <a-row style="height: 16.6%;width: 100%;">材料局部安全系数</a-row>
                <a-row style="height: 16.6%;width: 100%;">试验类型</a-row>
                <a-row style="height: 16.6%;width: 100%;">抗拉强度壁厚效应</a-row>
                <a-row style="height: 17%;width: 100%;">S-N曲线应力比</a-row>
              </a-col>
              <a-col :span="12" style="height: 100%;margin-top: 3px">
                <a-row style="height: 16.6%;width: 100%;"><input type="text" v-model="input_data.Ak"/></a-row>
                <a-row style="height: 16.6%;width: 100%;"><input type="text" v-model="input_data.sur"/></a-row>
                <a-row style="height: 16.6%;width: 100%;"><input type="text" v-model="input_data.Vm"/></a-row>
                <a-row style="height: 16.6%;width: 100%;">
                  <select style="width: 70%;height: 60%;"  v-model="input_data.nor">
                    <option value="1">标准</option>
                    <option value="2">拉伸</option>
                  </select>
                </a-row>
                <a-row style="height: 16.6%;width: 100%;">
                  <select style="width: 70%;height: 60%" v-model="input_data.Rm1">
                    <option value="1">是</option>
                    <option value="2">否</option>
                  </select>
                </a-row>
                <a-row style="height: 17%;width: 100%;">0</a-row>
              </a-col>
            </a-col>
          </a-row>
        </a-row>
        <a-row style="height:40%;width: 100%;border-radius: 3px" class="data_container">
          <a-row style="height: 8%;width: 100%;background: #D7D7D7;border-radius: 3px">疲劳安全系数输入参数</a-row>
          <a-row style="height: 92%;width: 100%;">
            <a-row style="height: 15%;width: 100%;text-align: center">
              <a-col :span="12" style="height: 100%;margin-top: 3px">
                <a-col :span="12" style="height: 100%;">计算载荷(kNm)</a-col>
                <a-col :span="12" style="height: 100%;"><input type="text" v-model="input_data.load"/></a-col>
              </a-col>
              <a-col :span="12" style="height: 100%;margin-top: 3px">
                <a-col :span="12" style="height: 100%;">计算应力(MPa)</a-col>
                <a-col :span="12" style="height: 100%;"><input type="text" v-model="input_data.F"/></a-col>
              </a-col>
            </a-row>
            <a-row style="height: 85%;width: 100%;border-radius: 3px">
              <a-col :span="18" style="height: 100%;border-radius: 3px" class="data_container">
                <a-row style="height: 10%;width: 100%;background: #D7D7D7;border-radius: 3px">载荷谱显示</a-row>
                <a-row style="height: 90%;width: 100%;">
                  <el-table
                      :data="tableData"
                      height="100%"
                      stripe
                      style="width: 100%">
                    <el-table-column
                        prop="data1"
                        label="最大载荷(kNm)"
                        width="180">
                    </el-table-column>
                    <el-table-column
                        prop="data2"
                        label="最小载荷(kNm)"
                        width="180">
                    </el-table-column>
                    <el-table-column
                        prop="data3"
                        label="循环次数">
                    </el-table-column>
                  </el-table>
                </a-row>
              </a-col>
              <a-col :span="6" style="height: 100%;text-align: center">
                <a-upload :show-upload-list="false" :maxCount="1"  :customRequest="customRequest" name="file">
                  <button style="margin-top: 20px;height: 20%;">导入载荷谱</button>
                </a-upload>
                <p>注：载荷谱文件格式为.xls或.xlsx格式，其各列参数为左表所示(无需表头)</p>
              </a-col>
            </a-row>
          </a-row>
        </a-row>
        <a-row style="height:5%;width: 100%">
          <a-col :span="18" style="height: 100%;"></a-col>
          <a-col :span="6" style="height: 100%;">
            <button style="height: 90%;width:70%;" @click="figure">计算</button>
          </a-col>
        </a-row>
        <a-row style="height:15%;width: 100%;border-radius: 3px" class="data_container">
          <a-row style="height: 20%;width: 100%;background: #D7D7D7;border-radius: 3px">输出参数</a-row>
          <a-row style="height: 20%;width: 100%;text-align: center">
            <a-col :span="12" style="height: 100%;margin-top: 3px;line-height: 80px">
              <a-col :span="12" style="height: 100%;">疲劳安全系数</a-col>
              <a-col :span="12" style="height: 100%;">{{result_data.result01}}</a-col>
            </a-col>
            <a-col :span="12" style="height: 100%;margin-top: 3px;line-height: 80px;">
              <a-col :span="12" style="height: 100%;">损伤率</a-col>
              <a-col :span="12" style="height: 100%;">{{result_data.result02}}</a-col>
            </a-col>
          </a-row>
        </a-row>
      </a-col>
      <a-col :span="14" style="height: 100%;">
        <a-row style="height: 80%;width: 100%;border-radius: 3px" class="data_container">
          <a-row style="height: 4%;width: 100%;background: #D7D7D7;border-radius: 3px">S-N曲线参考图样</a-row>
          <a-row style="height: 96%;width: 100%;">
            <img :src='require("@/assets/image/image_47_1.jpg")' style="height: 100%;width: 100%;">
          </a-row>
        </a-row>
        <a-row style="height: 20%;width: 100%;border-radius: 3px;text-align: center" class="data_container">
          <a-col :span="12" style="height: 100%;margin-top: 3px">
            <a-col :span="12" style="height: 100%;text-align: center">
              <a-row style="height: 33.3%;width: 100%;">上限点循环次数N1</a-row>
              <a-row style="height: 33.3%;width: 100%;">上限点应力范围值△σ1</a-row>
              <a-row style="height: 33.4%;width: 100%;"> 第1段曲线材料常数m1</a-row>
            </a-col>
            <a-col :span="12" style="height: 100%;">
              <a-row style="height: 33.3%;width: 100%;">{{result_data.result03}}</a-row>
              <a-row style="height: 33.3%;width: 100%;">{{result_data.result04}}</a-row>
              <a-row style="height: 33.4%;width: 100%;">{{result_data.result05}}</a-row>
            </a-col>
          </a-col>
          <a-col :span="12" style="height: 100%;margin-top: 3px">
            <a-col :span="12" style="height: 100%;">
              <a-row style="height: 33.3%;width: 100%;">转折点循环次数ND</a-row>
              <a-row style="height: 33.3%;width: 100%;"> 转折点应力范围值△σ*A</a-row>
              <a-row style="height: 33.4%;width: 100%;">第2段曲线材料常数m2</a-row>
            </a-col>
            <a-col :span="12" style="height: 100%;">
              <a-row style="height: 33.3%;width: 100%;">{{result_data.result06}}</a-row>
              <a-row style="height: 33.3%;width: 100%;">{{result_data.result07}}</a-row>
              <a-row style="height: 33.4%;width: 100%;">{{result_data.result08}}</a-row>
            </a-col>
          </a-col>
        </a-row>
      </a-col>
    </a-row>
  </div>
</template>

<script>
import {filetext, firedelete, HammersMith_S_N} from "@/api/file";

export default {
name: "hammersmith_S_N",
  created() {
    document.title = '合金钢件疲劳强度计算'
    this.$store.state.file.key = 47
  },
  mounted(){
    //绑定页面退出事件
    window.onbeforeunload= (e)=>{
      e = e || window.event;
      if (e) {
        e.returnValue = '关闭提示';
      }
      this.delete()//调用自己的方法
      // Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+
      return '关闭提示';
    };

  },
  data(){
    return{
      form2:{
        uuids:[]
      },
      visible: false,
      confirmLoading: false,
      input_data:this.$store.state.file.dataList[47],
      result_data:{
        result01: "",
        result02: "",
        result03: "",
        result04: "",
        result05: "",
        result06: "",
        result07: "",
        result08: "",
      },
      tableData: [],
      xz1:'标准',
      xz2:'是'
    }
  },
  methods:{
    //同步请求删除载荷谱数组的方法
    async delete(){
      // await axios.get("http://localhost:7001/hellow").then(res => {
      // })
      this.form2.uuids=this.form2.uuids.toString();//将载荷谱文件数组转成字符串
      await firedelete(this.form2).then(res => {//这里需要用箭头函数，如果不用箭头函数里面的this就不是外面那个this
        console.log(res);
      })
    },
    customRequest(data){
      const formData=new FormData()
      formData.append('fileName',data.file)
      filetext(formData).then(res=>{
        this.tableData.splice(0);
        this.input_data.uuid=res.data.uuid;
        this.form2.uuids.push(res.data.uuid);
        console.log(res.data.filedata);
        for (let i=0;i<res.data.filedata.length;i++){
          this.tableData.push({
            data1:res.data.filedata[i][0],
            data2:res.data.filedata[i][1],
            data3:res.data.filedata[i][2],
          })
        }
      }).catch(error=>{
        console.log(error)
      })
    },
    figure(){
      if(this.input_data.uuid=="")
        this.$message.warning("请先导入载荷谱")
      else {
        HammersMith_S_N(this.input_data).then(res => {
          console.log(res);
          this.result_data.result01 = res[6].result;
          this.result_data.result02 = res[7].result;
          this.result_data.result03 = res[0].result;
          this.result_data.result04 = res[1].result;
          this.result_data.result05 = res[2].result;
          this.result_data.result06 = res[3].result;
          this.result_data.result07 = res[4].result;
          this.result_data.result08 = res[5].result;
        }).catch(error => {
          console.log(error)
        })
      }
    },
    handleChange(){

    },
    showModal() {
      this.visible = true;
    },
    //点击ok
    handleOk() {
      this.visible = false;
    },
    //点击cancel
    handleCancel() {
      console.log('Clicked cancel button');
      this.visible = false;
    },
  }
}
</script>

<style scoped>
input{
  width: 70%;
  text-align: center;
}
.data_container{
  border: 0.5px solid rgba(231, 231, 231, 0.486);
  border-radius: 5px;
  box-shadow:2px 2px 3px #aaaaaa;
}
</style>